﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dos.Model;

public partial class webmx_program_banner_Set : PageBase
{
    public temple_Contents ad;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] != null && Request.QueryString["id"] != string.Empty)
        {
            
            ad = DB.Context.From<temple_Contents>()
                .Select(s => new { s.ID, s.Title, s.Depict, s.Photo, s.Attachment, s.CategoryID, s.SortID, s.AddTime, s.IsDel })
                .Where(w => w.ID == int.Parse(Request.QueryString["id"]))
                .First();
            if (IsPostBack)
            {
                string imgname;
                HttpPostedFile imgFile = HttpContext.Current.Request.Files[0];
                if (imgFile != null && imgFile.ContentLength > 0)
                {
                    imgname = Guid.NewGuid().ToString() + imgFile.FileName.Split('.')[1];
                    string savePath = Server.MapPath("~/upload/Banner/" + imgname);
                    imgFile.SaveAs(savePath);
                    ad.Photo = imgname;
                }
                ad.Title = Request.Form["txtname"].ToString();
                ad.Attachment = Request.Form["txtlink"].ToString();
                ad.SortID = int.Parse(Request.Form["txtsort"].ToString());
                ad.AddUser = (int)Session["manage"];
                DB.Context.Update(ad);
                AlertRedirect("编辑成功!", "set.aspx?id=" + Request.QueryString["id"]);
            }
        }
        else
            Response.Redirect("list.aspx");
    }
}